package org.marsdonne.audits;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import java.util.Date;

/**
 * 预期异常（审计）域
 * 用于追溯异常情况的产生及趋势
 */
@Entity
@Getter
@Setter
@EntityListeners(AuditingEntityListener.class)
@NoArgsConstructor
public class Exception extends LoggedEntity {
    @Column(nullable = false)
    private String serviceId;//服务标识

    @Column(nullable = false)
    private String processId;//进程标识

    @Column(nullable = false)
    private String type;//异常标识

    @Column(nullable = false)
    private String stackTrace;

    public Exception(String serviceId, String processId, Date dateCaught, String type, String stackTrace) {
        this.serviceId = serviceId;
        this.processId = processId;
        this.dateLogged = dateCaught;
        this.type = type;
        this.stackTrace = stackTrace;
    }

    public Exception(Caught caught) {
        this(caught.getServiceId(), caught.getProcessId(), caught.getDateCaught(), caught.getType(), caught.getStackTrace());
    }
}
